import Vue from 'vue'
import store from '../store/index';
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// const routes = [
//   {
//     path: '/',
//     name: 'Index',
//     component:  ()=> import('../views/Index.vue')
//   },
//   {
//     path: '/about',
//     name: 'About',
//     component: ()=> import('../views/About.vue')
//   }
// ]
import routes from "./routes.js";
const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
    if (localStorage.token) { // 判断当前的token是否存在 ； 登录存入的token
      next();
    } else {
      next({
        path: '/Login',
        query: {
          redirect: to.fullPath
        } 
      })
    }
  } else {
    next();
  }
});
export default router